import 'bgcContentSave.dart'; // 导入 TaskTagBo
import 'pacsunUserBo.dart';
import 'taskRecordBo.dart';

class DraftModel {
  final int id;
  final String aid;
  final PacsunUserBo? pacsunUserBo;
  final String title;
  final String content;
  final String richContent;
  final List<String> images;
  final int taskRecordId;
  final TaskRecordBo? taskRecordBo;
  final List<TaskTagBo> taskTagBoList;
  final String status;
  final String? thumbnail;
  final bool detached;
  final String? videos;

  DraftModel({
    required this.id,
    required this.aid,
    this.pacsunUserBo,
    required this.title,
    required this.content,
    required this.richContent,
    this.images = const [],
    this.taskRecordId = 0,
    this.taskRecordBo,
    this.taskTagBoList = const [],
    this.status = 'DRAFT',
    this.thumbnail,
    this.detached = false,
    this.videos,
  });

  factory DraftModel.fromJson(Map<String, dynamic> json) {
    return DraftModel(
      id: json['id'] as int,
      aid: json['aid'] as String,
      pacsunUserBo: json['pacsunUserBo'] != null
          ? PacsunUserBo.fromJson(json['pacsunUserBo'])
          : null,
      title: json['title'] as String? ?? '',
      content: json['content'] as String? ?? '',
      richContent: json['richContent'] as String? ?? '',
      images: List<String>.from(json['images'] ?? []),
      taskRecordId: json['taskRecordId'] as int? ?? 0,
      taskRecordBo: json['taskRecordBo'] != null
          ? TaskRecordBo.fromJson(json['taskRecordBo'])
          : null,
      taskTagBoList: (json['taskTagBoList'] as List<dynamic>?)
              ?.map((item) => TaskTagBo.fromJson(item))
              .toList() ??
          [],
      status: json['status'] as String? ?? 'DRAFT',
      thumbnail: json['thumbnail'] as String?,
      detached: json['detached'] as bool? ?? false,
      videos: json['videos'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> json = {
      'id': id,
      'aid': aid,
      'pacsunUserBo': pacsunUserBo?.toJson(),
      'title': title,
      'content': content,
      'richContent': richContent,
      'images': images,
      'taskRecordId': taskRecordId,
      'taskRecordBo': taskRecordBo?.toJson(),
      'taskTagBoList': taskTagBoList.map((item) => item.toJson()).toList(),
      'status': status,
      'thumbnail': thumbnail,
      'detached': detached,
    };

    if (videos != null) json['videos'] = videos;

    return json;
  }
}
